import VueRouter from 'vue-router'

//路由组件
import HomeContainer from './components/tarbar/HomeContainer.vue'
import MemberContainer from './components/tarbar/MemberContainer.vue'
import SearchContainer from './components/tarbar/SearchContainer.vue'
import ShopcarContainer from './components/tarbar/ShopcarContainer.vue'
import NewsList from './components/news/newslist.vue'
import NewsInfo from './components/news/newsinfo.vue'
import PhotosList from './components/photos/PhotosList.vue'
import PhotoInfo from './components/photos/PhotoInfo.vue'
import GoodsList from './components/goods/GoodsList.vue'
import GoodsInfo from './components/goods/GoodsInfo.vue'
import GoodsDesc from './components/goods/GoodsDesc.vue'
import GoodsComment from './components/goods/GoodsComment.vue'

// 3. 创建路由对象
var router = new VueRouter({
  routes: [
    { path: '/', redirect: '/home'},
    { path: '/home', component: HomeContainer },
    { path: '/member', component: MemberContainer },
    { path: '/search', component: SearchContainer },
    { path: '/shopcar', component: ShopcarContainer },
    { path: '/home/newslist', component: NewsList },
    { path: '/home/newsinfo/:id', component: NewsInfo },
    { path: '/home/photoslist', component: PhotosList ,meta:{keepalive:true}},
    { path: '/home/photoInfo/:id', component: PhotoInfo, },
    { path: '/home/goodslist', component: GoodsList ,meta:{keepalive:true}},
    { path: '/home/goodsinfo/:id', component: GoodsInfo},
    { path: '/home/goodsdesc/:id', component:GoodsDesc, name: 'goodsdesc'  },
    { path: '/home/goodscomment/:id', component: GoodsComment, name: 'goodscomment' }
  ],
  //设置进入页面时滚动条初始位置 注：此方法打包后，如果以本地文件形式打开则会报错
  // scrollBehavior (to, from, savedPosition) {
  //   if(savedPosition){
  //     return savedPosition;
  //   }else{
  //     return { x: 0, y: 0 }
  //   }    
  // },
  
  linkActiveClass:'mui-active'  //覆盖替换路由类router-link-active实现当前项高亮
})

//设置进入页面时滚动条初始位置方法2 注：此方法无法指定单个组件页面
// router.beforeEach((to, from, next) => { 
//   window.scrollTo(0,0);
//   next();
// });

// 把路由对象暴露出去
export default router